package com.helwen.tools.zhijiang;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/***
*
*把读取到的数据存入到excel文件中
*@author:Dell
*@date:2021/6/27 16:10
*@return:
 * @return null
*/
public class PoiExcel {
    /*
     *POI写入Excle文件内容
     */

    public static void main(String[] args) {
//创建工作薄
        HSSFWorkbook workbook=new HSSFWorkbook();
//创建sheet
        HSSFSheet sheet=workbook.createSheet();
//创建第一行row
        HSSFRow header=sheet.createRow(0);
//创建单元格并插入表头
        HSSFCell cell=null;
        String[] infos={"id","name","gender"};
        for(int i=0;i<infos.length;i++){
            cell=header.createCell(i);
            cell.setCellValue(infos[i]);
        }
//
        HSSFRow body=null;
        for(int i=1;i<=10;i++){
            body=sheet.createRow(i);
            cell=body.createCell(0);
            cell.setCellValue(i+"");
            cell=body.createCell(1);
            cell.setCellValue("user_"+i);
            cell=body.createCell(2);
            cell.setCellValue(i+"");
        }

//创建文件
        File file=new File("D:\\poi_1119.xls");
        try {
            file.createNewFile();
        } catch (IOException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        }
//文件输出流
        try {
            FileOutputStream stream=new FileOutputStream(file);
//写入
            workbook.write(stream);
//关闭输出流
            stream.close();
        } catch (IOException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
